<template>
  <div></div>
</template>
<script>
let timer = null
export default {
  props: {
    interval: {
      // 间隔时间,毫秒
      type: Number,
      default: 3000,
    },
    run: {
      //是否暂停
      type: Boolean,
      default: true,
    },
    once: {
      //立即执行一次
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {}
  },
  computed: {},
  watch: {},
  mounted() {
    if (this.once) {
      this.$emit('move')
    }
    const _this = this
    timer = setInterval(() => {
      if (_this.run) {
        this.$emit('move')
      }
    }, this.interval)
  },
  beforeDestroy() {
    if (timer) {
      clearInterval(timer) // 在Vue实例销毁前，清除定时器
    }
  },
  methods: {},
}
</script>
<style scoped></style>
